package com.eis.persist.model.user;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.eis.admin.mvc.bean.UserBean;
import com.eis.persist.model.base.BasePersist;


public class PersistUser extends BasePersist implements Serializable {
	private static final long serialVersionUID = -4881795753400160377L;
	private int id;
	private String name;
	private String password;
	private String email;
	private PersistSysGroup persistSysGroup;
	private PersistBizGroup persistBizGroup;
	private List<PersistUserPreferFunction> persistUserPreferFunction;
	
	public PersistUser() {
	}
	
	public PersistUser(UserBean filter) {
		this.name = filter.getUserName();
		if (filter.getBizGroup() != 0) {
			this.persistBizGroup = new PersistBizGroup();
			persistBizGroup.setId(filter.getBizGroup());
		}
		
		if (filter.getSysGroup() != 0) {
			this.persistSysGroup = new PersistSysGroup();
			persistSysGroup.setId(filter.getSysGroup());
		}
	}
	
	public PersistUser(Map<String, Object> userAndGroup) {
		this.id = (Integer) userAndGroup.get("id");
		this.name = (String) userAndGroup.get("name");
		this.password = (String) userAndGroup.get("password");
		this.email = (String) userAndGroup.get("email");
		
		if (userAndGroup.get("sysGroupId") != null && (Integer)userAndGroup.get("sysGroupId") > 0) {
			this.persistSysGroup = new PersistSysGroup(
					(Integer) userAndGroup.get("sysGroupId"),
					(String) userAndGroup.get("sysGroupName"),
					(String) userAndGroup.get("sysGroupDescription")
			);
		}
		
		if (userAndGroup.get("bizGroupId") != null && (Integer)userAndGroup.get("bizGroupId") > 0) {
			this.persistBizGroup = new PersistBizGroup(
					(Integer) userAndGroup.get("bizGroupId"),
					(String) userAndGroup.get("bizGroupName"),
					(String) userAndGroup.get("bizGroupDescription"),
					userAndGroup.get("isConfiged") != null ? (Integer) userAndGroup.get("isConfiged") != 0 : false,
					(Integer) (userAndGroup.get("parentId") != null ? userAndGroup.get("parentId") : 0)
			);
		}
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		if (name != null) name = name.trim(); 
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public PersistSysGroup getSysGroup() {
		return persistSysGroup;
	}
	public void setSysGroup(PersistSysGroup persistSysGroup) {
		this.persistSysGroup = persistSysGroup;
	}
	public PersistBizGroup getBizGroup() {
		return persistBizGroup;
	}
	public void setBizGroup(PersistBizGroup persistBizGroup) {
		this.persistBizGroup = persistBizGroup;
	}
	public List<PersistUserPreferFunction> getUserPreferFunction() {
		return persistUserPreferFunction;
	}
	public void setUserPreferFunction(List<PersistUserPreferFunction> persistUserPreferFunction) {
		this.persistUserPreferFunction = persistUserPreferFunction;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
}
